﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using hou_elearning.Entity;
using hou_elearning.Business;

public partial class Admin_control_ucChambaikiemtra : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            napDLLKhoahoc();
        }
    }
    private void napDLLKhoahoc()
    {
        List<KhoahocEntity> listKhoahoc = KhoahocBRL.GetAll();
        if (listKhoahoc.Count > 0)
        {
            ddlKhoahoc.DataSource = listKhoahoc;
            ddlKhoahoc.DataTextField = "sTenkhoahoc";
            ddlKhoahoc.DataValueField = "PK_iKhoahocID";
            ddlKhoahoc.DataBind();
           
        }else
            divThongbao.InnerHtml = "<p class='info' id='warning'><span class='info_inner'>Không có khóa học nào để hiển thị!</span></p>";
      

    }
    protected void ddlKhoahoc_SelectedIndexChanged(object sender, EventArgs e)
    {
        divThongbao.InnerHtml = "";
        // nạp danh sách kiểm tra theo khóa học
        Int64 PK_iKhoahocID = Int64.Parse( ddlKhoahoc.SelectedValue);
        List<KiemtraEntity> listKiemtra = KiemtraBRL.GetByFK_iKhoahocID(PK_iKhoahocID);
        if (listKiemtra.Count > 0)
        {
            ddlKiemtra.DataSource = listKiemtra;
            ddlKiemtra.DataTextField = "sTenbaikiemtra";
            ddlKiemtra.DataValueField = "PK_iKiemtraID";
            ddlKiemtra.DataBind();
        }
        else
            divThongbao.InnerHtml = "<p class='info' id='warning'><span class='info_inner'>Khóa học chưa có kì kiểm tra nào!</span></p>";
      

    }
    protected void btnThamgia_Click(object sender, EventArgs e)
    {
       // hiện form danh sách bài
        danhsachbaikt.Visible = true;
        //load grid view những bài kiếm tra chưa chấm của kì kiểm tra
        List<ThongtinbaikiemtraEntity> listbaikiemtrachuacham = ThongtinbaikiemtraBRL.GetBy_FK_iKiemtraID_iTrangthai(int.Parse(ddlKiemtra.SelectedValue),0);
        if (listbaikiemtrachuacham.Count > 0)
        {
            //bind gridview
            grvDSkiemtrachuacham.DataSource = listbaikiemtrachuacham;
            grvDSkiemtrachuacham.DataBind();
        }
        else
            divThongbao.InnerHtml = "<p class='info' id='warning'><span class='info_inner'>Không có bài kiểm tra chưa chấm!</span></p>";
      

    }
    protected void grvDSkiemtrachuacham_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label label = (Label)e.Row.FindControl("lblHocvien");
            NguoidungEntity oHocvien = NguoidungBRL.GetOne(int.Parse(label.Text));
            if (oHocvien != null)
                label.Text = oHocvien.sHoten;
            oHocvien = null;

        }
    }
    protected void grvDSkiemtrachuacham_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int iIndex;
        Int64 PK_iThongtinbaikiemtraID;
        iIndex = Convert.ToInt32(e.CommandArgument);
        GridViewRow row = grvDSkiemtrachuacham.Rows[iIndex];
        PK_iThongtinbaikiemtraID = Int64.Parse(row.Cells[0].Text);
        if (e.CommandName == "cmdChambai")
        {
            Session["PK_iThongtinbaikiemtraID"] = PK_iThongtinbaikiemtraID;
            Response.Redirect(ResolveUrl("~/Admin/?page=Chambaituluan"));
        }
    }
}